--[[ scheme_type: generic author: Alundaio --]] -------------------------------------- actid = 188116 evaid = 188116 -------------------------------------- local function validate(npc,vid) if (vid and vid < 4294967295 and npc:accessible(vid) and vid ~= npc:level_vertex_id()) then return db.used_level_vertex_ids[vid] == nil or db.used_level_vertex_ids[vid] == npc:id() end return false end local function lmove(npc,vid,st) if (vid == nil or vid >= 4294967295) then return end if (db.used_level_vertex_ids[vid] == npc:id()) then npc:set_dest_level_vertex_id(vid) return vid end if (st.vid) then db.used_level_vertex_ids[st.vid] = nil end if not (npc:accessible(vid)) then local vtemp = VEC_ZERO vid, vtemp = npc:accessible_nearest(vid and level.vertex_position(vid) or npc:position(), vtemp ) end db.used_level_vertex_ids[vid] = npc:id() st.vid = vid npc:set_dest_level_vertex_id(vid) return vid end local function lmove_ns(npc,vid,st) if (vid == nil or vid >= 4294967295) then return end if (db.used_level_vertex_ids[vid] == npc:id()) then npc:set_dest_level_vertex_id(vid) return vid end if (st.vid) then db.used_level_vertex_ids[st.vid] = nil end if not (npc:accessible(vid)) then local vtemp = VEC_ZERO vid, vtemp = npc:accessible_nearest(vid and level.vertex_position(vid) or npc:position(), vtemp ) end st.vid = vid npc:set_dest_level_vertex_id(vid) return vid end ----------------------------------------------------------------------------------------- -- EVALUATOR RADIO IN HELI ----------------------------------------------------------------------------------------- class "evaluator_radio_in_heli" (property_evaluator) function evaluator_radio_in_heli:__init(npc,name,storage) super (nil, name) self.st = storage end function evaluator_radio_in_heli:evaluate() --utils_data.debug_write("eva_radio_in_heli") local npc = self.object if not (npc:alive()) then return false end if (is_empty(db.heli)) then return false end if (IsWounded(npc)) then return false end local st = db.storage[npc:id()] if (st) and (st.help_wounded and st.help_wounded.selected_id ~= nil or st.active_scheme == "camper") then return false end if not (utils_obj.is_day()) then return false end if (xr_conditions.surge_started()) then return false end local squad = get_object_squad(npc) if not (squad) then return false end if not (squad:commander_id() == npc:id()) then return false end if (get_object_story_id(squad.id)) then return false end if (get_object_story_id(npc:id())) then return false end local be = npc:best_enemy() if not (be) then return false end local comm = character_community(npc) for id,o in pairs(db.heli) do if (se_heli.se_helicopters[id] and se_heli.se_helicopters[id].help_id == nil and se_heli.se_helicopters[id].community == comm) then return true end end return false end ----------------------------------------------------------------------------------------- -- ACTION RADIO IN HELI ----------------------------------------------------------------------------------------- class "action_radio_in_heli" (action_base) function action_radio_in_heli:__init (npc,name,storage) super (nil,name) self.st = storage end function action_radio_in_heli:initialize() action_base.initialize(self) local npc = self.object if (npc:path_type() ~= game_object.level_path) then npc:set_path_type(game_object.level_path) end npc:set_desired_position() npc:set_desired_direction() end function action_radio_in_heli:try_go_cover(npc,ene_pos) --utils_data.debug_write(strformat("action_radio_in_heli:try_go_cover")) local pos = npc:position() local vid = utils_obj.find_close_cover(npc,pos,ene_pos,1) if (validate(npc,vid)) then return lmove(npc,vid,self.st) end end function action_radio_in_heli:execute() action_base.execute(self) --utils_data.debug_write("act_radio_in_heli") local npc = self.object local be = npc:best_enemy() if not (be) then return end if (self.st.vid == nil) then self:try_go_cover(npc,be:position()) end if (self.st.vid == nil or npc:level_vertex_id() == self.st.vid or npc:position():distance_to_sqr(level.vertex_position(self.st.vid)) <= 3) then local tg = time_global() self.st.state = not self.st.state and random_choice("guard_rac","hide_rac") or self.st.state state_mgr.set_state(npc,self.st.state) local squad = get_object_squad(npc) if (squad) then xr_sound.set_sound_play(npc:id(),"backup") local comm = character_community(npc) for id,o in pairs(db.heli) do if (se_heli.se_helicopters[id]) then if (se_heli.se_helicopters[id].help_id == nil and se_heli.se_helicopters[id].community == comm) then heli_alife.force_target_destination(id,squad.id) end end end if (xr_combat_ignore.fighting_with_actor_npcs[npc:id()]) then save_var(db.actor,"heli_enemy_flag",true) end local function set_heli_flag(obj) if (db.storage[obj:id()]) then db.storage[obj:id()].heli_enemy_flag = true end end if (be:id() ~= 0) then utils_obj.execute_script_on_squad(be,set_heli_flag) end if not (self.st.dont_spam) then if (dynamic_news_manager and ui_options.get("alife/dynamic_news/heli_call_news") and (math.random(1,100)/100) < 0.5) then dynamic_news_manager.get_dynamic_news():RadioInHeli(npc,be) end self.st.dont_spam = true end end else self.st.vid = utils_obj.send_to_nearest_accessible_vertex(npc,self.st.vid) end end function action_radio_in_heli:finalize() action_base.finalize(self) end --------------------------------------------------------- ---------------------- binder --------------------------- function setup_generic_scheme(npc,ini,scheme,section,stype,temp) local st = xr_logic.assign_storage_and_bind(npc,ini,"radio_in_heli",section,temp) end function add_to_binder(npc,ini,scheme,section,storage,temp) if not npc then return end local manager = npc:motivation_action_manager() if not manager then return end if (not npc:alive()) or (character_community(npc) == "zombied" or npc:section() == "actor_visual_stalker") then manager:add_evaluator(evaid,property_evaluator_const(false)) temp.needs_configured = false return end local evaluator = evaluator_radio_in_heli(npc,"eva_radio_in_heli",storage) temp.action = action_radio_in_heli(npc,"act_radio_in_heli",storage) if not evaluator or not temp.action then return end manager:add_evaluator(evaid,evaluator) temp.action:add_precondition(world_property(stalker_ids.property_alive,true)) temp.action:add_precondition(world_property(stalker_ids.property_danger, false)) temp.action:add_precondition(world_property(evaid,true)) temp.action:add_effect(world_property(evaid,false)) manager:add_action(actid,temp.action) end function configure_actions(npc,ini,scheme,section,stype,temp) if not npc then return end local manager = npc:motivation_action_manager() if not manager or not temp.action then return end --temp.action:add_precondition(world_property(xr_evaluators_id.state_mgr + 1,true)) temp.action:add_precondition(world_property(xr_evaluators_id.sidor_wounded_base,false)) temp.action:add_precondition(world_property(xr_evaluators_id.wounded_exist,false)) --[[ if (_G.schemes["rx_ff"]) then temp.action:add_precondition(world_property(rx_ff.evaid,false)) end --]] if (_G.schemes["gl"]) then temp.action:add_precondition(world_property(rx_gl.evid_gl_reload,false)) end if (_G.schemes["npc_vs_box"]) then temp.action:add_precondition(world_property(axr_npc_vs_box.evaid,false)) end --[[ if (_G.schemes["facer"]) then temp.action:add_precondition(world_property(xrs_facer.evid_facer,false)) temp.action:add_precondition(world_property(xrs_facer.evid_steal_up_facer,false)) end --]] local action local p = { stalker_ids.action_combat_planner, xr_actions_id.state_mgr + 1, xr_actions_id.state_mgr + 2, xr_actions_id.alife } for i=1,#p do --printf("ACTION_ALIFE_ID(axr_radio_in_heli.configure_actions): " .. tostring(p[i])) action = manager:action(p[i]) if (action) then action:add_precondition(world_property(evaid,false)) end end end function disable_generic_scheme(npc,scheme,stype) local st = db.storage[npc:id()][scheme] if st then st.enabled = false end end function npc_add_precondition(action) if not action then return end action:add_precondition(world_property(evaid,false)) end